package smu.ui;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ExpandableListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;

import android.widget.SimpleExpandableListAdapter;
import android.widget.Toast;

//导入其他包
import smu.ui.others.*;
import smu.ui.widget.*;

public class MainActivity extends ExpandableListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        System.out.println("sss");
        //类别
        ArrayList<HashMap<String,String>> groups = new ArrayList<HashMap<String,String>>();
        HashMap<String,String> group1 = new HashMap<String,String>();
        group1.put("group","事件");
        groups.add(group1);
        HashMap<String,String> group2 = new HashMap<String,String>();
        group2.put("group","布局");
        groups.add(group2);
        HashMap<String,String> group3 = new HashMap<String,String>();
        group3.put("group","控件");
        groups.add(group3);
        HashMap<String,String> group4 = new HashMap<String,String>();
        group4.put("group","其他");
        groups.add(group4);
        
        //子类
        ArrayList<HashMap<String,String>> child1 = new ArrayList<HashMap<String,String>>();
        HashMap<String,String> child1Data1 = new HashMap<String,String>();
        child1Data1.put("child","事件一");
        child1.add(child1Data1);
        HashMap<String,String> child1Data2 = new HashMap<String,String>();
        child1Data2.put("child","事件二");
        child1.add(child1Data2);
        
        ArrayList<HashMap<String,String>> child2 = new ArrayList<HashMap<String,String>>();
        HashMap<String,String> child2Data1 = new HashMap<String,String>();
        child2Data1.put("child","FrameLayout");
        child2.add(child2Data1);
        HashMap<String,String> child2Data2 = new HashMap<String,String>();
        child2Data2.put("child","LinearLayout");
        child2.add(child2Data2);
        HashMap<String,String> child2Data3 = new HashMap<String,String>();
        child2Data3.put("child","Table Layout");
        child2.add(child2Data3);
        HashMap<String,String> child2Data4 = new HashMap<String,String>();
        child2Data4.put("child","RelativeLayout");
        child2.add(child2Data4);
        
        
        ArrayList<HashMap<String,String>> child3 = new ArrayList<HashMap<String,String>>();
        HashMap<String,String> child3Data1 = new HashMap<String,String>();
        child3Data1.put("child","ExpandableList");
        child3.add(child3Data1);
        HashMap<String,String> child3Data2 = new HashMap<String,String>();
        child3Data2.put("child","ListView");
        child3.add(child3Data2);
        HashMap<String,String> child3Data3 = new HashMap<String,String>();
        child3Data3.put("child","Dialog");
        child3.add(child3Data3);
        
        
        ArrayList<HashMap<String,String>> child4 = new ArrayList<HashMap<String,String>>();
        HashMap<String,String> child4Data1 = new HashMap<String,String>();
        child4Data1.put("child","Styles样式");
        child4.add(child4Data1);
        HashMap<String,String> child4Data2 = new HashMap<String,String>();
        child4Data2.put("child","theme主题");
        child4.add(child4Data2);
        HashMap<String,String> child4Data3 = new HashMap<String,String>();
        child4Data3.put("child","其他一");
        child4.add(child4Data3);
        
        ArrayList<ArrayList<HashMap<String,String>>> childs = new  ArrayList<ArrayList<HashMap<String,String>>>();
        childs.add(child1);
        childs.add(child2);
        childs.add(child3);
        childs.add(child4);
        
        SimpleExpandableListAdapter  adapter = new SimpleExpandableListAdapter(
        		this,
        		groups,R.layout.main_groups, new String[]{"group"}, new int[]{R.id.itemGroup},
        		childs,R.layout.main_item, new String[]{"child"}, new int[]{R.id.itemChild} 
        );
        setListAdapter(adapter);
        
    }

	@Override
	public boolean onChildClick(ExpandableListView parent, View v,
			int groupPosition, int childPosition, long id) {
		Toast.makeText(MainActivity.this, "groupPosition:"+groupPosition+"childPosition:"+childPosition, Toast.LENGTH_SHORT).show();
		Intent intent = new Intent();
		if (groupPosition == 0) {
			
		} else if(groupPosition == 1) {
			
		} else if(groupPosition == 2) {
			switch(childPosition){
			case 0:
				intent.setClass(MainActivity.this,ExpandableList.class);
				break;
			case 1:
				intent.setClass(MainActivity.this,List.class);
				break;
			case 2:
				intent.setClass(MainActivity.this, DialogActivity.class);
				break;
			default:
				break;
			}
		} else {
			switch(childPosition){
			case 0:
				intent.setClass(MainActivity.this, StylesActivity.class);
				break;
			case 1:
				intent.setClass(MainActivity.this, ThemesActivity.class);
				break;
			default:
				break;
			}
		}
		MainActivity.this.startActivity(intent);
		return super.onChildClick(parent, v, groupPosition, childPosition, id);
	}
    
    
	
	
    
}